import java.util.Arrays;

/**
 * @ClassName Day2LC821
 * @Description 821. 字符的最短距离
 * @Author clockTown
 * @Date 2021/9/11 8:26
 * @Version 1.0
 */
class Day2LC821 {

}

class Day2LC821vV0 {
    public int[] shortestToChar(String s, char c) {
        int[] res = new int[s.length()];
        char[] strs = s.toCharArray();
        int idx = s.length() - 1;
        for (int i = 0; i < strs.length; i++) {
            if (strs[i] == c){
                idx = i;
            }
            res[i] = Math.abs(i - idx);
        }
        idx = 0;
        for (int i = strs.length - 1; i >= 0; i--) {
            if (strs[i] == c){
                idx = i;
            }
            res[i] = Math.min(Math.abs(i - idx), res[i]);
        }
        return res;
    }
}
